<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UserSecurityInput.ascx.cs" Inherits="admin_webparts_URLSecurity_UserSecurityInput" %>
<%@ Import Namespace="NTTHAO.Common.BL" %>
<%@ Import Namespace="NTTHAO.CommonWeb" %>
<script type="text/javascript">
NTTHAO.namespace('page');

NTTHAO.page.urlAllow = new Array();

<%
    try
    {
        URLMap map = new URLMap();
        URLSecurity[] listSecurity = map.GetAllUrlPermission(this._EditingUser.ID);%>
    <%if (listSecurity != null) for (int i = 0; i < listSecurity.Length; i++)
          {%>
      NTTHAO.page.urlAllow[NTTHAO.page.urlAllow.length] = {urlid: <%=listSecurity[i].URLID%>, allow: <%=listSecurity[i].AllowRequest%>};
      <% } %>
<%
    }
    catch (Exception) { }
%>

function doCheckAll(o) {
    var objUrls = document.getElementsByName("chkUrl");
    if(objUrls && objUrls.length) {
        for(var i = 0; i < objUrls.length; i++) {
            objUrls[i].checked = o.checked;
        }
    } else if(objUrls) {
        objUrls.checked = o.checked;
    }
}

function doCheck() {
    var objAll = document.getElementById("chkAll");
    var objUrls = document.getElementsByName("chkUrl");
    
    var allCheck = true;

    if(objUrls && objUrls.length) {
        for(var i = 0; i < objUrls.length; i++) {
            if(!objUrls[i].checked) {
                allCheck = false;
                break;
            }
        }
        objAll.checked = allCheck;
    } else if(objUrls) {
        objAll.checked = objUrls.checked;
    }
}

YAHOO.util.Event.onDOMReady(function() {
    for(var i = 0; i < NTTHAO.page.urlAllow.length; i++) {
        var objUrl = document.getElementById('chkUrl_' + NTTHAO.page.urlAllow[i].urlid);
        if(objUrl != null) {
            objUrl.checked = NTTHAO.page.urlAllow[i].allow > 0 ? true : false;
        }
    }
    doCheck();
});
</script>
<div class="tip" style="margin-top: 10px;">
	<h1><%=LanguageUtility.GetLanguageText("PERMISSION_BY_USER", Session)%></h1>
</div>
<form id="UserSercurity" runat="server">
<p style="text-align: left;">
    <span id="spSave" class="yui-button yui-link-button yuibtn yuibtn-icon btnsave"><span class="first-child"><asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save" /></span></span>
    <span id="spCancel1" class="yui-button yui-link-button yuibtn yuibtn-icon btncancel"><span class="first-child"><input id="btnCancel1" type="button" value="<%=LanguageUtility.GetLanguageText("CANCEL", Session)%>" onclick="javscript: location.href='?type=user&action=list';" /></span></span>
</p>
<table cellspacing="0" cellpadding="0" border="1" class="grid" style="margin: 10px auto;">
    <tr class="even">
        <td align="right" style="width: 140px;">
            <%=LanguageUtility.GetLanguageText("USERNAME", Session)%>:
        </td>
        <td><b><%=this._EditingUser.UserName %></b></td>
    </tr>
    <tr class="odd">
        <td align="right">
            <%=LanguageUtility.GetLanguageText("ALLOW_REQUEST", Session)%>:
        </td>
        <td>
            <% if (this._URLList != null)
               {%>
            <table cellspacing="0" cellpadding="0" border="1" class="grid" style="width: auto;">
                <tr class="even">
                    <td>
                        <input type="checkbox" id="chkAll" name="chkUserAll" value="-1" onclick="doCheckAll(this);" />
                    </td>
                    <td align="left" style="width: 150px;"><label for="chkAll"><b><%=LanguageUtility.GetLanguageText("CHECK_ALL", Session)%></b></label></td>
                </tr>
               <%
                for (int i = 0; i < this._URLList.Rows.Count; i++)
                {%>
                <tr class="odd">
                    <td>
                        <input type="checkbox" id="chkUrl_<%=this._URLList.Rows[i][URLMap.ID__COLUMN_NAME] %>" name="chkUrl" value="<%=this._URLList.Rows[i][URLMap.ID__COLUMN_NAME] %>" onclick="doCheck();" />
                    </td>
                    <td align="left"><label for="chkUrl_<%=this._URLList.Rows[i][URLMap.ID__COLUMN_NAME] %>"><%=this._URLList.Rows[i][URLMap.URL__COLUMN_NAME]%></label></td>
                </tr> 
                  <%}%>
            </table>
               <%}%>
        </td>
    </tr>
</table>
<p style="text-align: left;">
    <span id="spSave2" class="yui-button yui-link-button yuibtn yuibtn-icon btnsave"><span class="first-child"><asp:Button ID="btnSave2" runat="server" OnClick="btnSave_Click" Text="Save" /></span></span>
    <span id="spCancel2" class="yui-button yui-link-button yuibtn yuibtn-icon btncancel"><span class="first-child"><input id="btnCancel2" type="button" value="<%=LanguageUtility.GetLanguageText("CANCEL", Session)%>" onclick="javscript: location.href='?type=user&action=list';" /></span></span>
</p>
</form>
<style type="text/css">
    #spCancel1, #spSave, #spCancel2, #spSave2 {font-size:1.1em; font-weight: bold; }
    #spCancel1 button, #spSave button, #spCancel2 button, #spSave2 button { font-family: Verdana,Arial,Helvetica,sans-serif; font-weight: bold; }
</style>
<script type="text/javascript"> 
YAHOO.util.Event.onContentReady("spCancel1", function () {
    var spCancel1 = new YAHOO.widget.Button("spCancel1");
    spCancel1.on("click", function () {location.href='?type=ser&action=list';}); 
});
YAHOO.util.Event.onContentReady("spCancel2", function () {
    var spCancel2 = new YAHOO.widget.Button("spCancel2");
    spCancel2.on("click", function () {location.href='?type=ser&action=list';}); 
});
YAHOO.util.Event.onContentReady("spSave", function () {
    var spSave = new YAHOO.widget.Button("spSave");
});
YAHOO.util.Event.onContentReady("spSave2", function () {
    var btnSave2 = new YAHOO.widget.Button("spSave2");
});
</script>